
#include "stdAfx.h"
#include "objectmanager.h"
#include "object.h"


std::vector<CBaseObject*> CObjectManager::m_pObjects;

CObjectManager::CObjectManager()
{
	m_pObjects.reserve(128);

}

CObjectManager::~CObjectManager()
{
	int nObjects = m_pObjects.size();

	for(int i = 0; i < nObjects ; i ++)
	{
		if( m_pObjects[i] )
		{
			delete m_pObjects[i];
			m_pObjects[i] = NULL;
		}
	}

	m_pObjects.clear();

}

bool CObjectManager::CheckRayCollision(const D3DXVECTOR3& vCameraDir,D3DXMATRIX* mtxCamera)
{
	int nObjects = m_pObjects.size();
	for(int i = 0 ; i < nObjects ; i ++)
		return m_pObjects[i]->CheckRayCollision(vCameraDir,mtxCamera);

	return false;
}
bool CObjectManager::RegisterObject(CBaseObject* Object)
{
	if( Object)
	{
		m_pObjects.push_back(Object);
		return true;
	}
	return false;

}
void CObjectManager::ObjectRender(LPDIRECT3DDEVICE9 pD3DDevice, CCamera* pCamera)
{
	for(int i= 0 ;i < m_pObjects.size(); i++)
	{
		m_pObjects[i]->Render(pD3DDevice,pCamera);
	}
}
